package com.school.aftersalemanagement.controller.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.school.aftersalemanagement.R;
import com.school.aftersalemanagement.entity.Record;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by winkyle on 2017/11/17.
 */

public class MaintenanceRecordAdapter extends BaseAdapter{
    private Context context;
    private List<Record> data;


    public MaintenanceRecordAdapter(Context context, List<Record> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        ViewHolder viewHolde = null;
        LayoutInflater myInflater = LayoutInflater.from(context);
        if (convertView == null) {
            convertView = myInflater.inflate(R.layout.adapter_maintenancerecord, null);
            viewHolde = new ViewHolder(convertView);
            viewHolde.date.setTextColor(Color.BLACK);
            viewHolde.person.setTextColor(Color.BLACK);
            viewHolde.bicycleInfo.setTextColor(Color.BLACK);
            viewHolde.adress.setTextColor(Color.BLACK);
            viewHolde.date.setTextSize(15);
            viewHolde.person.setTextSize(15);
            viewHolde.bicycleInfo.setTextSize(15);
            viewHolde.adress.setTextSize(15);
            convertView.setTag(viewHolde);
        } else {
            viewHolde = (ViewHolder) convertView.getTag();
        }
        viewHolde.date.setText(data.get(i).getCreate_time());
        viewHolde.person.setText(data.get(i).getRepair_person() );
        viewHolde.bicycleInfo.setText(data.get(i).getBike_number());
        viewHolde.adress.setText(data.get(i).getFence_id());
        if(i%2==0)
            convertView.setBackgroundColor(Color.rgb(228,228,228));
        else
            convertView.setBackgroundColor(Color.WHITE);
        return convertView;
    }
    public class ViewHolder {
        @BindView(R.id.maintenancerecord_bicycleInfo)
        TextView bicycleInfo;
        @BindView(R.id.maintenancerecord_adress)
        TextView adress;
        @BindView(R.id.maintenancerecord_date)
        TextView date;
        @BindView(R.id.maintenancerecord_person)
        TextView person;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
